package com.ruoyi.system.service.impl;

import com.ruoyi.common.constant.CacheKeyConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.IRedisTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class RedisTemplateServiceImpl implements IRedisTemplateService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String getId(String tpl) {
        Date nowDate = DateUtils.getNowDate();
        String nowDateString = DateUtils.parseDateToStr(DateUtils.YYMMDD, nowDate);
        String cacheKey = CacheKeyConstants.getTempletString(tpl, nowDateString);
        String id = String.format("%s%04d", DateUtils.parseDateToStr(DateUtils.YYMMDDHHMMSS, nowDate), redisTemplate.opsForValue().increment(cacheKey));
        return id;
    }
}
